package oop.lab.console;

import oop.lab.console.screen.Screen;
import oop.lab.domain.board.Board;
import oop.lab.domain.board.PieceColor;

public class BoardViewer {
    private Board board;

    public BoardViewer(Board board) {
        this.board = board;
    }

    public void display(Screen screen) {
        int size = board.getSize();
        // 列标题
        for (int j = 0; j < size; j++) {
            screen.print(0, 2 + j * 2, (char) ('A' + j));
        }
        // 棋盘内容
        for (int i = 0; i < size; i++) {
            // 行号
            screen.print(i + 1, 0, (char) ('1' + i));
            screen.print(i + 1, 1, ' ');
            for (int j = 0; j < size; j++) {
                PieceColor piece = board.getPiece(i, j);
                char c = '·';
                if (piece == PieceColor.BLACK)
                    c = '●';
                else if (piece == PieceColor.WHITE)
                    c = '○';
                screen.print(i + 1, 2 + j * 2, c);
                // 每格后加空格
                if (2 + j * 2 + 1 < board.getSize())
                    screen.print(i + 1, 2 + j * 2 + 1, ' ');
            }
        }
    }

}